package com.nuaa.controller.admin;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.nuaa.controller.base.BaseController;
import com.nuaa.domain.user.admin.AdminInfo;
import com.nuaa.service.inter.AdminInfoServiceInter;
import com.nuaa.utils.SessionKey;



/**
 * 管理员用户控制类
 * @author sevn
 *
 */
@Controller
@RequestMapping("admin/user")
public class UserController extends BaseController{

	private final static String contentType = "text/html;charset=utf-8";
	@Autowired
	private AdminInfoServiceInter adminInfoService;
	
	@RequestMapping(value="/show", method = RequestMethod.GET)
	public String show(Model model,HttpSession session){		
		model.addAttribute("user", session.getAttribute(SessionKey.UserInfoKey));
		return "admin/user/show";
	}
	/**
	 * heaven夏
	 */
	/**返回我的首页页面*/
	@RequestMapping("mainpage")
	public String getMainPage(){
		return "admin/user/mainpage";
	}
	
	@RequestMapping(value="/update",method = RequestMethod.POST)
	public String update(Model model,AdminInfo adminInfo,HttpSession session,HttpServletResponse response){
		AdminInfo sessAdmin = (AdminInfo) session.getAttribute(SessionKey.UserInfoKey);
		adminInfo.setLogin_name(sessAdmin.getLogin_name());
		adminInfo.setLogin_password(sessAdmin.getLogin_password());
		adminInfoService.update(adminInfo);
		session.setAttribute(SessionKey.UserInfoKey, adminInfo);
		
		response.setContentType(contentType);
		PrintWriter out;
		try {
			out = response.getWriter();
			out.println("更新成功！");
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}
